package edu.qhst.resource.controller.front;

import edu.qhst.common.constant.ApiRouterConsts;
import edu.qhst.common.constant.SystemConfigConsts;
import edu.qhst.common.resp.BaseResponse;
import edu.qhst.common.resp.ResultUtils;
import edu.qhst.config.MinioProperties;
import edu.qhst.resource.dto.UploadRespDto;
import edu.qhst.resource.service.MinioService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.RequestParam;

@Tag(name = "FrontResourceController", description = "前台-资源模块")
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_RESOURCE_URL_PREFIX)
@RequiredArgsConstructor
@Slf4j
public class FrontResourceController {

    private final MinioService minioService;

    private final MinioProperties minioProperties;

    @Operation(summary = "上传图片")
    @PostMapping("/uploadImg")
    @SneakyThrows
    public BaseResponse<UploadRespDto> upload(@RequestParam(name = "file")MultipartFile file) {
        String bucketname = minioProperties.getBucketName();
        return ResultUtils.success(minioService.uploadFile(file, bucketname));
    }
}
